<template>
  <div class="warpper-box sendSalary">
    <enterprise-select v-if="userInfo.type == 4" ref="enterprise" @enterpriseChange="enterpriseChange"></enterprise-select>
    <a-card style="margin-top: 10px;">
      <div style="display: flex;justify-content: flex-start;align-items: flex-start;">
        <form-create v-model="params.fApi" :rule="params.rule" :option="params.option" @btn-search-click="loadTable(true)" @btn-reset-click="reset" />
      </div>
    </a-card>
    <a-card style="margin-top: 10px;">
      <a-table :columns="table.columns" :data-source="table.loadData" :pagination="table.pagination"
        @change="handleTableChange" rowKey="backfillId">
        <!-- 操作栏-->
        <span slot="action" slot-scope="text, record">
          <!-- 编辑模块 | 字段 -->
          <span v-show="record.status == 0">
            <a-popconfirm title="是否确认结算？" ok-text="确认" cancel-text="取消" @confirm="resolveHandle(record)">
              <a>确认结算</a>
            </a-popconfirm>
            <a-divider type="vertical" />
            <a-popconfirm title="是否确认拒绝？" ok-text="确认" cancel-text="取消" @confirm="rejectHandle(record)">
              <a>拒绝</a>
            </a-popconfirm>
            <a-divider type="vertical"></a-divider>
          </span>
          <a @click="makeCost(record)">详情</a>
        </span>
      </a-table>
    </a-card>
  </div>
</template>

<script>
import store from '@/store'
import EnterpriseSelect from "@/components/human/enterpriseSelect.vue"
import {
  PARAMS_SERVICE_GET,
  COLUMNS_SERVICE_GET
} from "./form"
import {
  OPTION_BLOCK,
  OPTION_INLINE
} from "../base_form"
import {
  getTablePage,
  salaryBackfillAudit
} from "@/api/human/salaryPayServiceGet"
import { mapGetters, mapActions } from 'vuex'
export default {
  name: 'serviceGet',
  components: {
    EnterpriseSelect
  },
  data() {
    return {
      params: {
        fApi: {},
        rule: PARAMS_SERVICE_GET,
        option: OPTION_INLINE,
      },
      table: {
        columns: COLUMNS_SERVICE_GET,
        loadData: [],
        pagination: {
          current: 1,
          pageSize: 10,
          total: 0,
          showSizeChanger: true,
					showQuickJumper: true,
          pageSizeOptions: ["10", "20", "50", "100"],
          showTotal: total => `共有 ${total} 条数据`,
        }
      },
      pagination: { current: 1, pageSize: 10 },

      enterpriseId: "", // 企业id
      enterpriseData: [], // 客户列表

      selectedRowKeys: [], // 选择的table数据id
      selectedRows: [], // 选择的table数据
    }
  },
  filters: {
    filterMore(value, num) {
      if (!value) return ''
      if (value.length > num) {
        return value.slice(0, num) + '...'
      }
      return value
    }
  },
  mounted() {
    window.addEventListener('keyup', this.keyDown);
    if (this.userInfo.type == 4) {
      this.$refs.enterprise.getEnterpriseData();
    } else {
      this.enterpriseId = this.userInfo.relationId
      this.loadTable(true);
    }
  },
  destroyed() {
    window.removeEventListener('keyup', this.keyDown);
  },
  beforeCreate() {
    this.events_form = this.$form.createForm(this, {
      name: 'events_form'
    })
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  created() {

  },
  methods: {
    // table复选框选择
    onSelectChange(selectedRowKeys, selectedRows) {
      // console.log('selectedRowKeys changed: ', selectedRowKeys);
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
    },
    // 获取企业员工列表
    async loadTable(flag) {
      let params = this.params.fApi.formData();
      if (flag) {
        this.table.pagination.current = 1;
        this.table.pagination.pageSize = 10;
      }
      params.enterpriseId = this.enterpriseId;
      params.pageNum = this.table.pagination.current;
      params.pageSize = this.table.pagination.pageSize;
      const { code, data } = await getTablePage(params);
      if (code === '1') {
        this.table.loadData = data.content;
        this.table.pagination.total = data.total || 0;
      }
    },
    handleTableChange(pagination) {
      this.table.pagination.current = pagination.current;
      this.table.pagination.pageSize = pagination.pageSize;
      this.loadTable(false);
    },
    // 补偿服务费明细
    makeCost(row) {
      row.enterpriseId = this.enterpriseId;
      row.inType = 'info';
      this.$router.push({ name: 'humanResourcesSendSalaryPayCode', query: row });
    },
    // 确认结算订单
    async resolveHandle(row) {
      let params = {
        backFillId: row.backfillId,
        status: 1
      }
      const { code } = await salaryBackfillAudit(params);
      if (code === '1') {
        this.$message.success('操作成功');
        this.isPay = false;
        this.loadTable(true);
      }
    },
    // 拒绝订单
    async rejectHandle(row) {
      let params = {
        backFillId: row.backfillId,
        status: 2
      }
      const { code } = await salaryBackfillAudit(params);
      if (code === '1') {
        this.$message.success('操作成功');
        this.loadTable(true);
      }
    },
    // 企业选择回调
    enterpriseChange(value) {
      this.enterpriseId = value;
      this.loadTable(true);
    },
    addLoad() {
      this.loadTable(true);
    },
    reset() {
      this.params.fApi.resetFields();
      this.loadTable(true);
    }
  }
}
</script>
<style lang="less"></style>